﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shop_Phone.COMM;

namespace Shop_Phone.UserControls
{
    public partial class dangky : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && Visible)
            {
            }
        }

        protected void btndangky_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtusername.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(txtmatkhau.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(txttenkhachhang.Text))
            {
                return;
            }

            try
            {
                EndUser vcontroller = new EndUser();
                Entities.khachhang vkhachhang = new Entities.khachhang();
                string errMsg = string.Empty;
                vkhachhang.Tendangnhap = txtusername.Text;
                vkhachhang.Matkhau = txtmatkhau.Text;
                vkhachhang.Email = txtemail.Text;
                vkhachhang.Hoten = txttenkhachhang.Text;
                vkhachhang.Sodienthoai = txtsdt.Text;
                vkhachhang.Diachi = txtdiachi.Text;
                vkhachhang.Trangthai = true;
                int result = vcontroller.save_khachhang(vkhachhang, ref errMsg);
                if (result > 0)
                {
                    Response.Redirect("~/login.aspx");
                }
                else
                {
                    Response.Redirect("~/dangky.aspx");
                }

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                
            }
        }
    }
}